import yaml

class DataService:
    @staticmethod
    def import_coordinates(excel_file):
        """导入控件坐标"""
        coordinates = []
        for module, controls in extract_all_coordinates(excel_file).items():
            for control_name, (x, y) in controls.items():
                coordinate = Coordinate(
                    module_id=get_module_id(module),
                    element_name=control_name,
                    x_coord=x,
                    y_coord=y
                )
                coordinates.append(coordinate)
        db.session.bulk_save_objects(coordinates)
        db.session.commit()

    @staticmethod
    def import_base_steps(yaml_file):
        """导入基础步骤"""
        with open(yaml_file) as f:
            data = yaml.safe_load(f)
            for module, steps in data['testcase_mapper'].items():
                for step_name, script in steps.items():
                    action, desc = step_name.split('-')
                    BaseStep.create_base_step({
                        'module_id': get_module_id(module),
                        'step_name': step_name,
                        'step_type': get_step_type(action),
                        'description': desc,
                        'script_content': script
                    }) 